package com.rocksdb;

import org.rocksdb.Options;
import org.rocksdb.RocksDB;
import org.rocksdb.RocksDBException;
import org.rocksdb.RocksIterator;

import java.util.ArrayList;
import java.util.List;

public class Example {

    static {
        RocksDB.loadLibrary();
    }

    private static final String dbPath = "/opt/study/rocksdb";

    public static void main(String[] args) {
        try (final Options options = new Options().setCreateIfMissing(true)){
            RocksDB db = RocksDB.open(options, dbPath);
            // write some data
            db.put("hello".getBytes(),"world".getBytes());
            // read data by hello
            System.out.println("get hello = "+new String(db.get("hello".getBytes())));

            try(RocksIterator iter = db.newIterator()) {
                for (iter.seekToFirst();iter.isValid();iter.next()) {
                    System.out.println("key:"+new String(iter.key()) + ",value:"+new String(iter.value()));
                }
            }
            List<String> list = new ArrayList<>();
            list.add("AAAA");
            list.add("BBBB");
            list.add("CCCC");
            list.add("DDDD");

        } catch (RocksDBException e) {
            e.printStackTrace();
        }
    }
}
